<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class message extends FOX_Controller {

	function __construct ()
	{
		parent::__construct();
        if(!$this->session->userdata('user_id')){
            redirect(site_url('nologin'));
        }
        $this->load->model('message_m');
	}
	public function index(){
        $user_id = $this->session->userdata('user_id');
        $this->message_m->update_user_message($this->session->userdata('user_id'));
        $data['total'] = $this->message_m->count_user_message($this->session->userdata('user_id'));
        $data['messages'] = $this->message_m->user_find_message(0,$this->config->item('page_message_list'),$this->session->userdata('user_id'));
		$data['foot_memu'] = 'member';
		$this->load->view('user_message',$data);
	}
	//删除消息通知
	public function del_msg(){
		$user_id = $this->session->userdata('user_id');
	    $message_id = $this->input->post('message_id');
	    if($message_id){
	    	$result = $this->message_m->del_user_message_by_id($message_id);
	    	if($result){
	    		$msg['info'] = "删除消息通知成功";
		        $msg['status'] = 1;
		        echo json_encode($msg);
	    	}else{
	    		$msg['info'] = "删除消息失败";
		        $msg['status'] = 0;
		        echo json_encode($msg);
	    	}
	    }else{
	    		$msg['info'] = "信息有误";
		        $msg['status'] = 0;
		        echo json_encode($msg);
	    }
	}
}
